<?php
/*
$aaa = new sendsms();
$str = $aaa->send('13580405060', "您的验证码是122");
echo "aaaa";
echo $str;
exit();
*/
class sendsms{
	
    //发送短信接口
    public function send($mobile, $content, $cell='', $crond_sendtime=''){
    	global $sms_username, $sms_password, $sms_companyname;
		$CorpID		= $sms_username;
		$Pwd		= $sms_password;
        $content	.= "【{$sms_companyname}】";
        $content = urlencode($content);
        $send_time	= date ('Y-m-d H:i:s');
		$query		= "CorpID=$CorpID&Pwd=$Pwd&Mobile=$mobile&Content=$content&Cell=$cell&SendTime=$crond_sendtime";
		
		//$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg'; 
		//$headers[] = 'Connection: Keep-Alive'; 
		$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'; 
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,"http://www.mb2e.com/sendutf8.php");
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
		// receive server response ...
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$str = curl_exec ($ch);
		curl_close ($ch);
		//echo $str;
		return $str;
		exit;

		// further processing ....


		$process = curl_init($url); 
		curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers); 
		curl_setopt($process, CURLOPT_HEADER, 1); 
		curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent); 
		if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file); 
		if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file); 
		curl_setopt($process, CURLOPT_ENCODING , $this->compression); 
		curl_setopt($process, CURLOPT_TIMEOUT, 30); 
		if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy); 
		curl_setopt($process, CURLOPT_POSTFIELDS, $data); 
		curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); 
		curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); 
		curl_setopt($process, CURLOPT_POST, 1); 
		$return = curl_exec($process); 
		curl_close($process); 


        /*
		$query		= "CorpID=$CorpID&Pwd=$Pwd&Mobile=$mobile&Content=$content&Cell=$cell&SendTime=$crond_sendtime";
		
        $host		= '211.152.9.213';
        $port		= 6600;
        $target		= '/Send.aspx';
        $length		= strlen($query);
		
        $header		= array();
        $header[]	= 'POST '.$target.' HTTP/1.1';
        $header[]	= 'Content-Length: '.$length;
		$header[]	= 'charset=utf-8';
		$header		= implode("\r\n", $header);
		$header		.= "\r\n\r\n".$query;
		
		$str = '';
		$fp = fsockopen($host, $port, $errno, $errstr, 30);
		if (!$fp) {
			echo "$errstr ($errno)<br />\n";
		} else {
			@fwrite($fp, $header, strlen($header));
			$p = chr(13).chr(10).chr(13).chr(10);
			$loop = 0;	
			while ($loop<100) {
				$str .= @fread($fp, 1);
				if (strpos($str,$p)>0) break;
			}
			$str = substr($str, strpos($str,'Content-Length:')+15);
			$loop = intval($str);
			$str = @fread($fp, $loop);
			fclose($fp);
		}
		return $str;
		*/
	}
	
    //获取网站注册的验证码
    public function getCheckCode($mobile){
		$checkcode	= rand(1000, 9999);
		$content	= '欢迎注册，您的验证码是'.$checkcode.'，10分钟内有效。';
		$status		= $this->send($mobile, $content);
		if ($status > 0) {
			
		} else {
			
		}
		return $checkcode;
	}
}

//$sendsms = new sendsms();
//echo $sendsms->getCheckCode('13544529054,18027196538,13538757457');
?>